package com.aimusic.domain.dto;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * WebSocket消息模型类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WebSocketMessage {
    private String type; // 消息类型：message, typing_status, heartbeat, read_ack等
    private String content; // 消息内容
    private String senderId; // 发送者ID
    private String receiverId; // 接收者ID
    private String messageId; // 消息ID
    private boolean isRead; // 是否已读
    private boolean isTyping; // 是否正在输入
    private long timestamp; // 时间戳

    // getter和setter方法
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getSenderId() {
        return senderId;
    }

    public void setSenderId(String senderId) {
        this.senderId = senderId;
    }

    public String getReceiverId() {
        return receiverId;
    }

    public void setReceiverId(String receiverId) {
        this.receiverId = receiverId;
    }

    public String getMessageId() {
        return messageId;
    }

    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }

    public boolean isRead() {
        return isRead;
    }

    public void setRead(boolean read) {
        isRead = read;
    }

    public boolean isTyping() {
        return isTyping;
    }

    public void setTyping(boolean typing) {
        isTyping = typing;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    // 转换为JSON字符串
    public String toJson() {
        JSONObject json = new JSONObject();
        json.put("type", this.type);
        json.put("content", this.content);
        json.put("senderId", this.senderId);
        json.put("receiverId", this.receiverId);
        json.put("messageId", this.messageId);
        json.put("isRead", this.isRead);
        json.put("isTyping", this.isTyping);
        json.put("timestamp", this.timestamp);
        return json.toJSONString();
    }
}
